#ifndef PEERMANAGER_H
#define PEERMANAGER_H

#include <QByteArray>
#include <QList>
#include <QObject>
#include <QTimer>
#include <QUdpSocket>
#include <QHostInfo>
class Network;
class Connection;

class PeerManager : public QObject
{
    Q_OBJECT

public:
    PeerManager(Network *m_network);

    void setServerPort(int port);
    void startBroadcasting();

signals:
    //void newConnection(Connection *connection);
    void newConnection(const QString &address);
    void leave(const QString &address);
    void shopDetection(const QUrl &url);
private slots:
    void readBroadcastDatagram();
    void sendBroadcastDatagram();
private:
    //void updateAddresses();
    bool isLocalHostAddress(const QHostAddress &address);
private:
    Network *m_network;
    QList<QHostAddress> broadcastAddresses;
    QList<QHostAddress> ipAddresses;
    QUdpSocket broadcastSocket;
    QTimer broadcastTimer;
    QString username;
    int serverPort;
};

#endif
